package org.jeecg.modules.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.system.entity.SysDepartRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 部门角色
 * @Author: jeecg-boot
 * @Date:   2020-02-12
 * @Version: V1.0
 */
public interface SysDepartRoleMapper extends BaseMapper<SysDepartRole> {
    /**
     * 根据用户id，部门id查询可授权所有部门角色
     * @param orgCode
     * @param userId
     * @return
     */
    public List<SysDepartRole> queryDeptRoleByDeptAndUser(@Param("orgCode") String orgCode, @Param("userId") String userId);
    @Select("select role_name from `sys_depart_role` where id=#{id}")
    String findDRnameById(@Param("id")String id);
    @Update("update `sys_depart_role_user` t1 left join(select id from `sys_depart_role` t2 where t2.depart_id=#{depId}) t3 on t1.drole_id=t3.id set t1.user_id=#{userId}")
    void handleDeptRole1(String depId, String userId);
    @Select("select t1.user_id from `sys_depart_role_user` t1,`sys_depart_role` t2 where t1.drole_id=t2.id and t2.depart_id=#{depId}")
    String findUserIdByDepId(String depId);
}
